<?php
namespace Home\Controller;
use Common\Controller\CommonController;
class ScController extends CommonController {
	
	function index(){
		$id=I('id');
		$where['aid']=$id;
		$count=M('sc')->where($where)->count();
		$page=new \Think\Page($count,10);
		$show=$page->show();	
		
		
		$re=M('sc')->where($where)->select();
		foreach ($re as $key => $value ) {
			$id=$value['id'];
			$value['num']=M('Apt')->where('sid='.$id)->count();
			$a[]=$value;	
		}
		$re=$a;
		$where1['id']=I('id');
		$res=M('area')->where($where1)->find();
		$this->assign('cid',$res['cid']);
		$this->assign('id',I('id'));
		$this->assign('list',$re);
		$this->display('index');
		
	
	}
	
	function addsc(){
		$id=I('id');
		$sc=I('sc');
		if($sc){
		$data=array('sc'=>$sc,'aid'=>$id);
		$re=M('sc')->add($data);	
		if($re){
		$this->redirect('sc/index',array('id'=>$id));	
		}
		}else{
		$this->assign('id',$id);
		$this->display('add');
		}
	}

	function delsc(){
		$where['id']=I('id');
		$aid=I('aid');
		$re=M('sc')->where($where)->delete();
		if($re){
		$this->redirect('sc/index',array('id'=>$aid));	
		}
	}
	
	
}